package com.hk.web.domain.lifeCycle.factory;

import com.hk.commons.enums.Whether;
import com.hk.web.domain.entity.Merchant;
import com.hk.web.domain.entity.MerchantUserAccount;
import com.hk.web.domain.entity.User;
import org.apache.commons.lang3.RandomStringUtils;

import java.util.UUID;

/**
 *
 * @author Antinomy
 * @date 17/11/1
 */
public class MerchantFactory {

    public static Merchant create(String merchantName, String merchantUrl) {
        Merchant merchant = new Merchant();

        merchant.setName(merchantName);
        merchant.setUrl(merchantUrl);

        String key = UUID.randomUUID().toString();
        merchant.setMerchantKey(key);

        String secret =  RandomStringUtils.randomAlphanumeric(32);
        merchant.setMerchantSecret(secret);

        merchant.setEnable(Whether.YES);

        return merchant;
    }

    public static MerchantUserAccount createMerchantUserAccount(Merchant merchant, User user) {
        MerchantUserAccount merchantUserAccount;
        merchantUserAccount = new MerchantUserAccount();
        merchantUserAccount.setMerchantAccountId(UUID.randomUUID().toString());
        merchantUserAccount.setMerchantKey(merchant.getMerchantKey());
        merchantUserAccount.setMobile(user.getName());
        merchantUserAccount.setUserId(user.getId());
        return merchantUserAccount;
    }
}
